package com.hghivln.controller.doctor;

import com.hghivln.aspectj.annotation.Log;
import com.hghivln.aspectj.enums.BusinessType;
import com.hghivln.pojo.dto.RegistrationDto;
import com.hghivln.pojo.dto.RegistrationFormDto;
import com.hghivln.pojo.dto.RegistrationQueryDto;
import com.hghivln.pojo.vo.AjaxResult;
import com.hghivln.service.PatientService;
import com.hghivln.service.RegistrationService;
import com.hghivln.utils.ShiroUtils;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

@RestController
@RequestMapping("doctor/registration")
public class RegistrationController {

    @Reference
    private RegistrationService registrationService;

    @Reference
    private PatientService patientService;

    /**
     * 查询挂号列表(有排班的科室)
     */
    @GetMapping("listDeptForScheduling")
    @HystrixCommand
    public AjaxResult listDeptForScheduling(@Validated RegistrationQueryDto registrationQueryDto) {
        return registrationService.listDeptForScheduling(registrationQueryDto);
    }

    /**
     * 根据身份证号查询患者信息
     */
    @GetMapping("getPatientByIdCard/{idCard}")
    @HystrixCommand
    public AjaxResult getPatientByIdCard(@PathVariable @Validated @NotBlank(message = "身份证号不能为空") String idCard) {
        return patientService.selectPatientByIdCard(idCard);
    }

    /**
     * 保存挂号信息
     */
    @PostMapping("addRegistration")
    @HystrixCommand
    @Log(title = "保存挂号信息",businessType = BusinessType.INSERT)
    public AjaxResult addRegistration(@RequestBody @Validated RegistrationFormDto registrationFormDto) {
        registrationFormDto.getRegistrationDto().setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return registrationService.addRegistration(registrationFormDto);
    }

    /**
     * 收费
     */
    @PostMapping("collectFee/{registrationId}")
    @HystrixCommand
    @Log(title = "收费",businessType = BusinessType.UPDATE)
    public AjaxResult collectFee(@PathVariable @Validated @NotBlank(message = "挂号流水单号不能为空") String registrationId) {
        return registrationService.collectFee(registrationId);
    }

    /**
     * 分页查询挂号信息
     */
    @GetMapping("queryRegistrationForPage")
    @HystrixCommand
    public AjaxResult collectFee(RegistrationDto registrationDto) {
        return registrationService.selectRegistrationForPage(registrationDto);
    }

    /**
     * 作废
     */
    @PostMapping("doInvalid/{registrationId}")
    @HystrixCommand
    @Log(title = "作废",businessType = BusinessType.DELETE)
    public AjaxResult doInvalid(@PathVariable @Validated @NotBlank(message = "挂号流水单号不能为空") String registrationId) {
        return registrationService.doInvalid(registrationId);
    }

    /**
     * 退号
     */
    @PostMapping("doReturn/{registrationId}")
    @HystrixCommand
    @Log(title = "退号",businessType = BusinessType.UPDATE)
    public AjaxResult doReturn(@PathVariable @Validated @NotBlank(message = "挂号流水单号不能为空") String registrationId) {
        return registrationService.doReturn(registrationId);
    }
}
